<html>
<head><meta charset="utf-8"><title>Floating point printing · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html">Floating point printing</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216131845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216131845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216131845">(Nov 09 2020 at 19:24)</a>:</h4>
<p>Are there any remaining known issues with floating point -&gt; string conversion?<br>
I'm quite surprised that the second line here prints the wrong value: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=047e2d133595647101121bb564b77661">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=047e2d133595647101121bb564b77661</a></p>



<a name="216133893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216133893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216133893">(Nov 09 2020 at 19:40)</a>:</h4>
<p>That is 16 correct diges. Why do you say it is wrong?</p>



<a name="216141432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216141432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216141432">(Nov 09 2020 at 20:52)</a>:</h4>
<p>the integer value has exactly 53 significant bits (1 leading zero, 10 trailing zeros), so it is precisely represented in <code>f64</code> too</p>



<a name="216141466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216141466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216141466">(Nov 09 2020 at 20:53)</a>:</h4>
<p>but Rust's minimal-round-trip algorithm for strings cuts that short</p>



<a name="216141505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216141505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216141505">(Nov 09 2020 at 20:53)</a>:</h4>
<p><code>"{.0?}"</code> does show it in full</p>



<a name="216150566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216150566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216150566">(Nov 09 2020 at 22:22)</a>:</h4>
<p>Yeah I would expect the debug representation to show the true value</p>



<a name="216266431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216266431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216266431">(Nov 10 2020 at 20:05)</a>:</h4>
<p>"True" value is a complicated question, though.  I <em>like</em> that the current display doesn't make me think that I could change it to <code>9223372036854774785u64</code> and still come back exactly.  (And if I increase the last sigfig of the current one, to <code>9223372036854776000_u64</code>, I do get that back.)</p>



<a name="216325175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Floating%20point%20printing/near/216325175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Floating.20point.20printing.html#216325175">(Nov 11 2020 at 09:50)</a>:</h4>
<p>There's an open issue about how <a href="https://github.com/rust-lang/rust/issues/70336">inconsistent the fixed precision rounding</a> is when formatting output. Although arguably Rust doesn't make any promises about <code>Display</code>ed output.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>